<template>
    <!-- 轮播图 -->
    <div>
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
            <van-swipe-item v-for="item in bannerList">
                <img :src=item.img alt="">
            </van-swipe-item>
        </van-swipe>
    </div>
    <!-- 横幅 -->
    <div>
        <van-notice-bar left-icon="volume-o" :scrollable="false">
            <van-swipe vertical class="notice-swipe" :autoplay="3000" :touchable="false" :show-indicators="false">
                <van-swipe-item v-for="it in seckliiList">{{ it.proname }}</van-swipe-item>
            </van-swipe>
        </van-notice-bar>
    </div>
    <!-- 秒杀区域 -->
    <div class="seckill">
        <van-image fit="fill" :src=i.img1 v-for="i in seckliiList" class="litbox" @click="confirmpro(i.proid)" />
    </div>
    <!-- 商品列表区域 -->
    <div>
        <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
            <van-list class="home-pro-list" v-model:loading="loading" :finished="finished" finished-text="没有更多了"
                @load="onLoad">
                <van-cell v-for="item in proList" :key="item.proid" @click="goToDetail(item.proid)">
                    <div class="pro-list-item">
                        <div class="list-item-img">
                            <img class="item-img" :src="item.img1" alt="" />
                        </div>
                        <div class="item-text">{{ item.proname }}</div>
                        <div class="item-price">￥{{ item.originprice }}</div>
                    </div>
                </van-cell>
            </van-list>
            <van-back-top bottom="110px"/>
        </van-pull-refresh>
    </div>
</template>

<script setup lang="ts">
import { ref, onMounted, type Ref } from 'vue';
import { GetBannerList, GetseckillList, GetPromsg } from '@/api/api';
import { useRouter } from 'vue-router';
import { useGoodList } from '@/Hooks/homehooks';

const router = useRouter()
const bannerList: Ref<any[]> = ref([])
const seckliiList: Ref<any[]> = ref([])
const {
    proList,
    loading,
    finished,
    refreshing,
    onLoad,
    onRefresh,
    goToDetail,
} = useGoodList();

const confirmpro = async (value: string) => {
    const res = await GetPromsg(value)
    router.push({
        path: '/detail',
        query: {
            id: res.data.data.proid
        }
    })
    console.log(res);
}

onMounted(async () => {
    const res2 = await GetseckillList()
    seckliiList.value = res2.data.data
    const res = await GetBannerList()
    if (res.data.code === '200') {
        bannerList.value = res.data.data
    }
})

</script>

<style lang="scss" scoped>
.home-pro-list {
    display: flex;
    flex-flow: wrap;
    justify-content: space-evenly;
    background-color: rgba(75, 84, 75, 0.1215686275);
    margin-top: 20px;

    .van-cell {
        width: 48%;
        margin-bottom: 15px;

        .pro-list-item {
            .list-item-img {
                width: 100%;
                height: 200px;

                .item-img {
                    display: block;
                    width: 100%;
                }
            }

            .item-text {
                display: -webkit-box;
                text-overflow: ellipsis;
                text-align: left;
                overflow: hidden;
                -webkit-box-orient: vertical;
                -webkit-line-clamp: 2;
                word-break: break-all;
                color: #222;
                margin: 10px 0;
            }

            .item-price {
                text-align: left;
                font-weight: bold;
                color: rgb(227, 37, 28);
            }
        }
    }
}

.notice-swipe {
    height: 40px;
    line-height: 40px;
}

.my-swipe .van-swipe-item {
    color: #fff;
    font-size: 20px;
    line-height: 150px;
    text-align: center;
    background-color: #39a9ed;
    height: 200px;
    width: 100%;

    img {
        height: 100%;
        width: 100%;
    }
}

.seckill {
    height: 75px;
    width: 100%;
    display: flex;
    justify-content: space-evenly;

    .litbox {
        height: 100%;
        width: 100%;

        img {
            height: 100%;
            width: 100%;
        }
    }
}
</style>